﻿using System.ComponentModel;
using System.Web.Services;
using SVTTranslateTextEngine.Properties;
using SVTTranslateTextEngine.TTChecker;
using SVTTranslateTextEngine.TTInputParams;
using SVTTranslateTextEngine.TTResults;

namespace SVTTranslateTextEngine
{
    /// <summary>
    /// Summary description for TTWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
    public class TTWebService : WebService
    {
        //Web methods to request system configurable parameters

        /// <summary>
        /// that are implemented for translation. E.g. “GOOGLE”, “BING”, etc. (“GOOGLE” is what we will develop first)
        /// </summary>
        /// <returns>Return a string array of vendor names</returns>
        [WebMethod]
        public string[] GetSupportedTranslateVendors()
        {
            return new[] {"GOOGLE"};
        }

        /// <summary>
        /// If source text length less than maximum lenght, that can be translated using the web method TranslateTextToText(…)
        /// </summary>
        /// <returns>Return the maximum length allowed of source text</returns>
        [WebMethod]
        public long GetMaxSizeTextToText()
        {
            return Settings.Default.TextToTextMaxLength;
        }

        /// <summary>
        /// The web service will be configured to allow/disallow translating text to a file
        /// </summary>
        /// <returns>Return Y or N if it supports translating text to a file</returns>
        [WebMethod]
        public string GetIsTranslateTextToFile()
        {
            return Settings.Default.TranslateTextToFile;
        }

        /// <summary>
        /// Configured the lanaguage is support.
        /// </summary>
        /// <param name="szVendorName">Translate engine's vendor name</param>
        /// <param name="szLang">language code </param>
        /// <returns>Return Y or N if szLang is a valid language supported</returns>
        [WebMethod]
        public bool GetIsValidLanguage(string szVendorName, string szLang)
        {
            return string.IsNullOrEmpty(new LanguageChecker().CheckIsSupported(szVendorName, szLang));
        }

        /// <summary>
        /// Confirm how many translates engine's vendor names can support the source language 
        /// </summary>
        /// <param name="szLang">language code </param>
        /// <returns>Return a string array of vendor names. E.g. “GOOGLE”, “BING”, etc.</returns>
        [WebMethod]
        public string[] GetSupportedTranslateLanguageVendors(string szLang)
        {
            return null;
        }

        /// <summary>
        /// Get the share folder path where saves the source context files and translation context file .
        /// </summary>
        /// <returns>share path</returns>
        [WebMethod]
        public string GetSourceContextFileSharePath()
        {
            return new TranslateManger().GetSourceContextShareDirPath();
        }

        /// <summary>
        /// Soap object contain the source text which will translate by the web mothed 
        /// </summary>
        /// <param name="textInput"></param>
        /// <returns>Return the translate text as string</returns>
        [WebMethod]
        public ToTextResult TranslateTextToText(TextInputParam textInput)
        {
            return new TranslateManger().TranslateToText(textInput);
        }

        /// <summary>
        /// This translate function by the model which input by the soap object , 
        /// and return the target context file path for the application getting the translation context .
        /// </summary>
        /// <param name="textInput">Input parameter for the soap source context </param>
        /// <returns>Return the target context file path </returns>
        [WebMethod]
        public ToFileResult TranslateTextToFile(TextInputParam textInput)
        {
            return new TranslateManger().TranslateToFile(textInput);
        }

        /// <summary>
        /// This translate function by the model which input by the file transfer on share folder , 
        /// and return the target context file path for the application getting the translation context .
        /// </summary>
        /// <param name="fileInput">Input parameter about translation information and file transmission information </param>
        /// <returns></returns>
        [WebMethod]
        public ToFileResult TranslateFileToFile(FileInputParam fileInput)
        {
            return new TranslateManger().TranslateToFile(fileInput);
        }

        /// <summary>
        /// Not confirmed 
        /// </summary>
        /// <param name="textInput"></param>
        /// <param name="execDbInput"></param>
        /// <returns></returns>
        [WebMethod]
        public UpdateDBResult TranslateTextToDB(TextInputParam textInput, ExecDBInputParam execDbInput)
        {
            return null;
        }

        /// <summary>
        /// Not confirmed 
        /// </summary>
        /// <param name="fileInput"></param>
        /// <param name="execDbInput"></param>
        /// <returns></returns>
        [WebMethod]
        public UpdateDBResult TranslateFileToDB(FileInputParam fileInput, ExecDBInputParam execDbInput)
        {
            return null;
        }
    }
}